package juc.design.guardedObject.TestGuardedObject3;

import java.util.Hashtable;
import java.util.Map;
import java.util.Set;

public class Mailboxes {
    private static Map<Integer, GuardedObjectV3> boxes = new Hashtable<>();
    private static int id = 1;
    // 产生唯一 id
    private static synchronized int generateId() {
        return id++;
    }
    //送完信后，进行等待删除
    public static GuardedObjectV3 getGuardedObjectV3(int id) {
        return boxes.remove(id);
    }
    public static GuardedObjectV3 createGuardedObjectV3() {
        GuardedObjectV3 go = new GuardedObjectV3(generateId());
        boxes.put(go.getId(), go);
        return go;
    }

    //获取所有的等待id，方便邮递员进行送信
    public static Set<Integer> getIds() {
        return boxes.keySet();
    }

}
